
import UIKit

class XSTabBarViewController: UITabBarController {
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        self.setValue(XSTabBar(), forKey: "tabBar")
        
        self.addchildVc(XSHomeViewController(), title: "首页", imageName: "tabbar_home")
        self.addchildVc(XSMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        self.addchildVc(XSDiscoveViewController(), title: "发现", imageName: "tabbar_discover")
        self.addchildVc(XSProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addchildVc(controller: UIViewController, title: String, imageName: String) {
        
        let nav = XSNavigationViewController(rootViewController: controller)
        
        controller.title = title
        nav.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        nav.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        self.addChildViewController(nav)
    }
}
